package cn.daisy.equipment.subject.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.RepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import cn.daisy.equipment.subject.domain.Subject;
import cn.daisy.equipment.subject.service.ISubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 设备类型Controller
 *
 * @author Kevin
 * @date 2022-10-12
 */
@Slf4j
@Api(tags = "设备类型")
@RestController
@RequestMapping("/equipment/subject")
public class SubjectController extends BaseController
{
    @Autowired
    private ISubjectService subjectService;

    /**
     * 查询设备类型列表
     */
    @ApiOperation(value = "设备类型列表")
    @PreAuthorize("@ss.hasPermi('equipment:subject:list')")
    @GetMapping("/list")
    public AjaxResult list(Subject subject)
    {
        List<Subject> list = subjectService.selectSubjectList(subject);
        return AjaxResult.success(list);
    }

    /**
     * 导出设备类型列表
     */
    @ApiOperation(value = "导出设备类型列表")
    @PreAuthorize("@ss.hasPermi('equipment:subject:export')")
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Subject subject)
    {
        List<Subject> list = subjectService.selectSubjectList(subject);
        ExcelUtil<Subject> util = new ExcelUtil<Subject>(Subject.class);
        util.exportExcel(response, list, "设备类型数据");
    }

    /**
     * 获取设备类型详细信息
     */
    @ApiOperation(value = "获取设备类型详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(subjectService.selectSubjectById(id));
    }

    /**
     * 新增设备类型
     */
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @ApiOperation(value = "新增设备类型")
    @PreAuthorize("@ss.hasPermi('equipment:subject:add')")
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subject subject)
    {
        return toAjax(subjectService.insertSubject(subject));
    }

    /**
     * 修改设备类型
     */
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @ApiOperation(value = "修改设备类型")
    @PreAuthorize("@ss.hasPermi('equipment:subject:edit')")
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subject subject)
    {
        return toAjax(subjectService.updateSubject(subject));
    }

    /**
     * 删除设备类型
     */
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @ApiOperation(value = "删除设备类型")
    @PreAuthorize("@ss.hasPermi('equipment:subject:remove')")
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subjectService.deleteSubjectByIds(ids));
    }
}
